/*
 * Copyright (C) 2003, Velocityme Partnership
 * PersonBean.java
 *
 * Created on 30 March 2003, 04:45
 */

package com.velocityme.entity;

import javax.ejb.*;
import javax.naming.*;
import java.rmi.*;
import javax.rmi.*;
import com.velocityme.interfaces.*;
import com.velocityme.valueobjects.PersonValue;
import java.util.Collection;
import java.util.Iterator;

/**
 * @author  Robert Crida Work
 * @ejb.bean
 *           type="CMP"
 *           cmp-version="2.x"
 *           name="Person"
 *           jndi-name="ejb/Person"
 *           view-type="local"
 * @ejb.transaction type="Required"
 *
 * @ejb.value-object match="*"
 *
 * @ejb.persistence table-name="person"
 *
 * @ejb.util generate="physical"
 *
 * @ejb.finder signature="java.util.Collection findAll()"
 *              query="SELECT OBJECT(o) FROM Person o WHERE o.contactableLocal.nodeLocal.dBObjectLocal.isDeleted = FALSE"
 *
 * @ejb.finder signature="java.util.Collection findBySearchAndRoles(com.velocityme.interfaces.SearchLocal searchLocal, com.velocityme.interfaces.TransitionLocal transitionLocal)"
 *              query="SELECT DISTINCT ua.userLocal.personLocal FROM Search s, IN (s.searchLevelsLocal) l, IN (l.nodesLocal) ln, UserAccess ua, Transition t, IN (t.responsibleRolesLocal) tr, Role r, Node n WHERE s=?1 AND t=?2 AND ua.roleLocal=r AND r = tr AND ua.nodeLocal=n AND n = ln"
// *              query="SELECT DISTINCT ua.userLocal.personLocal FROM Search s, IN (s.searchLevelsLocal) l, UserAccess ua, Transition t, Role r, Node n WHERE s=?1 AND t=?2 AND ua.roleLocal=r AND r MEMBER OF t.responsibleRolesLocal AND ua.nodeLocal=n AND n MEMBER OF l.nodesLocal"
 *
 * @ejb.finder signature="java.util.Collection findBySearchGroupAndRoles(com.velocityme.interfaces.SearchLocal searchLocal, com.velocityme.interfaces.TransitionLocal transitionLocal)"
 *              query="SELECT DISTINCT u.personLocal FROM Search s, IN (s.searchLevelsLocal) l, IN (l.nodesLocal) ln, GroupAccess ga, IN (ga.groupLocal.usersLocal) u, Transition t, IN (t.responsibleRolesLocal) tr, Role r, Node n WHERE s=?1 AND t=?2 AND ga.roleLocal=r AND r = tr AND ga.nodeLocal=n AND n = ln"
 *
 * @ejb.finder signature="java.util.Collection findBySearchAndRoles(com.velocityme.interfaces.SearchLocal searchLocal, com.velocityme.interfaces.TaskStateMachineLocal taskStateMachineLocal)"
 *              query="SELECT DISTINCT ua.userLocal.personLocal FROM Search s, IN (s.searchLevelsLocal) l, IN (l.nodesLocal) ln, UserAccess ua, TaskStateMachine t, IN (t.interestedRolesLocal) tr, Role r, Node n WHERE s=?1 AND t=?2 AND ua.roleLocal=r AND r = tr AND ua.nodeLocal=n AND n = ln"
 *
 * @ejb.finder signature="java.util.Collection findBySearchGroupAndRoles(com.velocityme.interfaces.SearchLocal searchLocal, com.velocityme.interfaces.TaskStateMachineLocal taskStateMachineLocal)"
 *              query="SELECT DISTINCT u.personLocal FROM Search s, IN (s.searchLevelsLocal) l, IN (l.nodesLocal) ln, GroupAccess ga, IN (ga.groupLocal.usersLocal) u, TaskStateMachine t, IN (t.interestedRolesLocal) tr, Role r, Node n WHERE s=?1 AND t=?2 AND ga.roleLocal=r AND r = tr AND ga.nodeLocal=n AND n = ln"
 *
 * @jboss.persistence create-table="true"
 *                    remove-table="false"
 */
public abstract class PersonBean implements EntityBean {
    
    /**
    * Context set by container
    */
    private javax.ejb.EntityContext m_entityContext;

    public void setEntityContext(javax.ejb.EntityContext entityContext) {
        m_entityContext = entityContext;
    }

    public void unsetEntityContext() {
        m_entityContext = null;
    }
  
    /** @ejb.create-method */
    public com.velocityme.interfaces.PersonPK ejbCreate(com.velocityme.interfaces.ContactableLocal p_contactableLocal,
                                                        com.velocityme.valueobjects.PersonValue p_value) throws CreateException {
        setPersonId(p_contactableLocal.getContactableId());
        // EJB 2.0 spec says return null for CMP ejbCreate methods.
        return null;
    }

    public void ejbPostCreate(com.velocityme.interfaces.ContactableLocal p_contactableLocal,
                              com.velocityme.valueobjects.PersonValue p_value) throws CreateException {
        // CMR relations must be set in ejbPostCreate
        setPersonValue(p_value);
        setContactableLocal(p_contactableLocal);
    }

    /**
     *  This gets a local object from a remote object.
     *  @ejb.interface-method view-type="remote"
     */
    public com.velocityme.interfaces.PersonLocal getLocal() {
        return (PersonLocal)m_entityContext.getEJBLocalObject();
    }
    
    /** @ejb.interface-method view-type="local" */
    public abstract com.velocityme.valueobjects.PersonValue getPersonValue();
    /** @ejb.interface-method view-type="local" */
    public abstract void setPersonValue(com.velocityme.valueobjects.PersonValue p_value);

    //=======================================================================
    //
    //                   ATTRIBUTES
    //
    //=======================================================================
      
    /**
     * @ejb.persistence column-name="personId"
     * @ejb.interface-method view-type="local"
     * @ejb.pk-field 
     */
    public abstract java.lang.Integer getPersonId();
    /** @ejb.interface-method view-type="local" */
    public abstract void setPersonId(java.lang.Integer personId);

   /**
     * @ejb.persistence column-name="firstName"
     * @ejb.interface-method view-type="local"
     */
    public abstract java.lang.String getFirstName();
    /** @ejb.interface-method view-type="local" */
    public abstract void setFirstName(java.lang.String firstName);

     /**
     * @ejb.persistence column-name="lastName"
     * @ejb.interface-method view-type="local"
     */
    public abstract java.lang.String getLastName();
    /** @ejb.interface-method view-type="local" */
    public abstract void setLastName(java.lang.String lastName);
    
    /**
     * @ejb.persistence column-name="jobTitle"
     * @ejb.interface-method view-type="local"
     */
    public abstract java.lang.String getJobTitle();
    /** @ejb.interface-method view-type="local" */
    public abstract void setJobTitle(java.lang.String jobTitle);
    
    //=======================================================================
    //
    //                   RELATIONSHIPS
    //
    //=======================================================================
    
    /**
     * @ejb.interface-method view-type="local"
     * @ejb.relation name="Person-Contactable"
     *               role-name="Person-has-a-Contactable"
     * @jboss.relation fk-column="contactableIdFk"
     *                 related-pk-field="contactableId"
     * @ejb.value-object match="*" 
     *                   aggregate="com.velocityme.valueobjects.ContactableValue"
     *                   aggregate-name="ContactableValue"
     */
    public abstract com.velocityme.interfaces.ContactableLocal getContactableLocal();
    /** @ejb.interface-method view-type="local" */
    public abstract void setContactableLocal(com.velocityme.interfaces.ContactableLocal contactableLocal);
    
    /**
     * @ejb.interface-method view-type="local"
     * @ejb.relation name="Person-User"
     *               role-name="Person-has-many-Users"
     */
    public abstract java.util.Collection getUsersLocal();
    /** @ejb.interface-method view-type="local" */
    public abstract void setUsersLocal(java.util.Collection users);
    
    /**
     * @ejb.interface-method view-type="local"
     * @ejb.relation name="Person-Time"
     *               role-name="Person-may-have-many-Times"
     */
    public abstract java.util.Collection getTimesLocal();
    /** @ejb.interface-method view-type="local" */
    public abstract void setTimesLocal(java.util.Collection times);
    
    /**
     * @ejb.interface-method view-type="local"
     * @ejb.relation name="Sprint-Team"
     *               role-name="Person-may-be-in-many-Sprints"
     * @jboss.relation fk-column="personId"
     *                 related-pk-field="sprintId"
     * @jboss.relation-table table-name="sprintteam"
     *                       create-table="true"
     *                       remove-table="false"
     */
    public abstract java.util.Collection getSprintsLocal();
    /** @ejb.interface-method view-type="local" */
    public abstract void setSprintsLocal(java.util.Collection sprints);
    
//=======================================================================
    //
    //                   MANAGEMENT METHODS
    //
    //=======================================================================
    
    /** 
     * @ejb.interface-method view-type="local"
     */
    public java.lang.String getName() {
        return getContactableLocal().getNodeLocal().getName();
    }
    
}
